package me.chan.apple;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.function.Predicate;

public class AppleFilter {

	public static boolean isGreen(Apple apple) {
		return "green".equals(apple.getColor());
	}
	
	public static boolean isHeavy(Apple apple) {
		return apple.getWeight() >= 60;
	}
	
	public static boolean isLight(Apple apple) {
		return apple.getWeight() <  60;
	}
	
	public static List<Apple> filterApples(List<Apple> list, Predicate<Apple> p) {
		List<Apple> appleList = new ArrayList<>();
		for (Apple apple: list) {
			if (p.test(apple)) {
				appleList.add(apple);
			}
		}
		return appleList;
	}
	
	public static void main(String[] args) {
	/*	List<Apple> list = filterApples(AppleCache.getAppleList(), AppleFilter::isGreen);
		System.out.println(list);
		List<Apple> heavyList = filterApples(AppleCache.getAppleList(), AppleFilter::isHeavy);
		System.out.println(heavyList);*/
		/*List<Apple> list = AppleCache.getAppleList();
		List<Apple> appleList1 = filterApples(list, (Apple a) -> a.getWeight() >= 60);
		System.out.println(appleList1);
		
		List<Apple> appleList2 = filterApples(list, (Apple a)->"green".equals(a.getColor()));
		System.out.println(appleList2);
	
		List<Apple> appleList = filterApples(list,  (Apple a)-> a.getWeight() <  60);
		System.out.println(appleList);
		
		List<Apple> appleList3 = filterApples(list, AppleFilter::isLight);
		System.out.println(appleList3);*/
		
		List<Apple> greenAppleList = filterApples(AppleCache.getAppleList(), 
					a ->  "green".equals(a.getColor()));
		System.out.println(greenAppleList);
	}
}
